﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rectangle
{
    class Rectangle:IComparable<Rectangle>, ICloneable
    {
        private double posX;
        private double posY;
        private double width;
        private double height;

        public Rectangle(double posX, double posY, double width, double height)
        {
            this.posX = posX;
            this.posY = posY;
            this.Width = width;
            this.Height = height;
        }

        public double PosX
        {
            get
            {
                return posX;
            }
            set
            {
                posX = value;
            }
        }

        public double PosY
        {
            get
            {
                return posY;
            }
            set
            {
                posY = value;
            }
        }

        public double Width
        {
            get
            {
                return width;
            }
            set
            {
                if (value < 0f)
                {
                    throw new ArgumentException("Width cannot be less than 0.");
                }
                width = value;
            }
        }

        public double Height
        {
            get
            {
                return height;
            }
            set
            {
                if (value < 0f)
                {
                    throw new ArgumentException("Height cannot be less than 0.");
                }
                height = value;
            }
        }

        private double Area()
        {
            double area = this.width * this.height;
            return area;
        }

        public override bool Equals(object obj)
        {
            bool result = this.PosX.Equals(((Rectangle)obj).PosX) && this.PosY.Equals(((Rectangle)obj).PosY) &&
                this.Width.Equals(((Rectangle)obj).Width) && this.Height.Equals(((Rectangle)obj).Height);
            return result;
        }

        #region IComparable<Rectangle> Members

        public int CompareTo(Rectangle other)
        {
            double firstArea = this.Area();
            double secondArea = other.Area();

            return firstArea.CompareTo(secondArea);
        }

        #endregion

        #region ICloneable Members

        public object Clone()
        {
            return new Rectangle(this.posX, this.posY, this.width, this.height);
        }

        #endregion
    }
}
